---
category: Date Time
contributors:
    - ValchanOficial
created: '2020-04-19'
title: 'Convert a date to YYYY-MM-DD format'
updated: '2021-10-13'
---

**JavaScript version**

```js formatYmd.js
// `date` is a `Date` object
const formatYmd = (date) => date.toISOString().slice(0, 10);
```

**TypeScript version**

```ts formatYmd.ts
const formatYmd = (date: Date): string => date.toISOString().slice(0, 10);
```

**Example**

```js example.js
formatYmd(new Date()); // 2020-05-06
```
